<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- /课程列表 开始 -->
    <section class="container">
      <header class="comm-title">
        <h2 class="fl tac">
          <span class="c-333">全部课程</span>
        </h2>
      </header>
      <section class="c-sort-box">
        <section class="c-s-dl">
          <dl>
            <dt>
              <span class="c-999 fsize14">课程类别</span>
            </dt>
            <dd class="c-s-dl-li">
              <ul class="clearfix">
                <li :class="{current:checkOne==-1}">
                  <a title="全部" @click="getAll" href="javascript:void(0)">全部</a>
                </li>

                <li :class="{current:index==checkOne}"
                    v-for="(subjectOne,index) in subjectList" :key="subjectOne.id">
                  <a :title="subjectOne.title" @click="selectOne(subjectOne.id,index)"
                     href="javascript:void(0)">{{subjectOne.title}}</a>
                </li>

              </ul>
            </dd>
          </dl>
          <dl>
            <dt>
              <span class="c-999 fsize14"></span>
            </dt>
            <dd class="c-s-dl-li">
              <ul class="clearfix">
                <li :class="{current:index==checkTwo}" v-for="(subjectTwo,index) in subjectTwoList"
                    :key="subjectTwo.id">
                  <a :title="subjectTwo.title"

                     @click="selectTwo(subjectTwo.id,index)"

                     href="#">{{subjectTwo.title}}</a>
                </li>

              </ul>
            </dd>
          </dl>
          <div class="clear"></div>
        </section>
        <div class="js-wrap">
          <section class="fr">
            <span class="c-ccc">
              <i class="c-master f-fM">1</i>/
              <i class="c-666 f-fM">1</i>
            </span>
          </section>
          <section class="fl">
            <ol class="js-tap clearfix">
              <li :class="{'current bg-orange': this.courseFrontVo.viewCount=='1'}">
                <a title="关注度" @click="byCase('viewCount')" href="#">关注度</a>
              </li>
              <li :class="{'current bg-orange': this.courseFrontVo.isNew=='1'}">
                <a title="最新" @click="byCase('isNew')" href="#">最新</a>
              </li>
              <li :class="{'current bg-orange': this.courseFrontVo.price=='1'}">
                <a title="价格" @click="byCase('price')" href="#">价格&nbsp;
                  <span>↓</span>
                </a>
              </li>
            </ol>
          </section>
        </div>
        <div class="mt40">
          <!-- /无数据提示 开始-->
          <section v-if="coursePage.records==null||coursePage.records==''" class="no-data-wrap">
            <em class="icon30 no-data-ico">&nbsp;</em>
            <span class="c-666 fsize14 ml10 vam">没有相关数据，小编正在努力整理中...</span>
          </section>
          <!-- /无数据提示 结束-->
          <article class="comm-course-list">
            <ul class="of" id="bna">
              <li v-for="course in coursePage.records" :key="course.id">
                <div class="cc-l-wrap">
                  <section class="course-img">
                    <img :src="course.cover" class="img-responsive" :alt="course.title">
                    <div class="cc-mask">
                      <a :href="'/course/'+course.id" title="开始学习" class="comm-btn c-btn-1">{{course.title}}</a>
                    </div>
                  </section>
                  <h3 class="hLh30 txtOf mt10">
                    <a :href="'/course/'+course.id" :title="course.title" class="course-title fsize18 c-333">{{course.title}}</a>
                  </h3>
                  <section class="mt10 hLh20 of">
                    <span class="fr jgTag bg-green">
                      <i v-show="Number(course.price)===0" class="c-fff fsize12 f-fA">免费</i>
                      <i v-show="Number(course.price)!==0" class="c-fff fsize12 f-fA">{{course.price}}</i>
                    </span>
                    <span class="fl jgAttr c-ccc f-fA">
                      <i class="c-999 f-fA" v-text="course.buyCount"></i>
                      |
                      <i class="c-999 f-fA">9634评论</i>
                    </span>
                  </section>
                </div>
              </li>

            </ul>
            <div class="clear"></div>
          </article>
        </div>
        <!-- 公共分页 开始 -->
        <div>
          <div class="paging">
            <a href="#" title @click="goToPage(1)">首</a>

            <a id="backpage"
               v-show="coursePage.hasPrevious"
               @click="goToPage(coursePage.current1-1)"
               href="#"
               title>&lt;</a>

            <a href="#" v-for="pages in coursePage.pages" :key="pages"
               @click="goToPage(pages)"
               title
               :class="{current:pages==coursePage.current1,undisable:pages==coursePage.current1}">
              {{pages}}</a>

            <a href="#" id="nextpage"
               v-show="coursePage.hasNext" @click="goToPage(coursePage.current1+1)"
               title>&gt;</a>

            <a href="#" @click="goToPage(coursePage.pages)">末</a>
            <div class="clear"></div>
          </div>
        </div>
        <!-- 公共分页 结束 -->
      </section>
    </section>
    <!-- /课程列表 结束 -->
  </div>
</template>
<script>
  import { subjectAll } from '@/api/subject'
  import { getCourseByCase } from '@/api/course'

  export default {
    data() {
      return {
        subjectList: [],
        subjectTwoList: [],
        checkOne: '-1',
        checkTwo: '-1',
        //分页信息 记录
        coursePage: {},
        //条件查询
        courseFrontVo: {
          subjectOneId: '',
          subjectTwoId: '',
          isNew: '',
          price: '',
          viewCount: ''
        }
      }
    },
    created() {
      this.getSubject()
      this.getCourseCase(1, 8)
    },
    methods: {
      //获取课程分类菜单
      getSubject() {
        subjectAll().then(response => {
          this.subjectList = response.data.data.data2
        })
      },
      //点击效果
      selectOne(oneId, index) {
        this.checkOne = index
        this.checkTwo = -1
        if (index !== -1) {
          this.courseFrontVo.subjectOneId = oneId
          this.subjectTwoList = this.subjectList[index].children
        } else {
          this.subjectTwoList = []
        }
      },
      selectTwo(twoId, index) {
        this.courseFrontVo.subjectTwoId = twoId
        this.checkTwo = index
        this.getCourseCase(1, 8)
        //  查询数据
      },
      getCourseCase(current, limit) {
        getCourseByCase(current, limit, this.courseFrontVo).then(response => {
          this.coursePage = response.data.data.data
        })
      },
      goToPage(current) {
        this.getCourseCase(current, 8, this.courseFrontVo)
      },
      //条件
      byCase(caseId) {
        if (caseId == 'isNew') {
          this.courseFrontVo.isNew = 1
          this.courseFrontVo.viewCount = ''
          this.courseFrontVo.price = ''
        }
        if (caseId == 'viewCount') {
          this.courseFrontVo.isNew = ''
          this.courseFrontVo.viewCount = '1'
          this.courseFrontVo.price = ''
        }
        if (caseId == 'price') {
          this.courseFrontVo.isNew = ''
          this.courseFrontVo.viewCount = ''
          this.courseFrontVo.price = '1'
        }
        getCourseByCase(1, 8, this.courseFrontVo).then(response => {
          this.coursePage = response.data.data.data
        })

      },
      getAll() {
        this.courseFrontVo = {}
        getCourseByCase(1, 8, this.courseFrontVo).then(response => {
          this.coursePage = response.data.data.data
        })
      }
    }
  }
</script>
